<template>
<!-- :visible.sync="stopVisible" -->
  <el-dialog :visible="true" width="450px" title=" 终止license" :close-on-click-modal="false" :show-close="false">
    <div class="dialog-body">
      <el-form label-width="110px" label-position="left">
        <el-form-item label="终止原因" class="required">
          <el-input
            placeholder="请输入终止原因"
            name='reason'
            type="textarea"
            v-model="stopForm.reason"
            v-validate="'required|maxLength128'"
          />
          <div v-show="errors.has('reason')" class="el-form-item__error">{{ errors.first('reason') }}</div>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="stopClose">取消</el-button>
      <el-button type="primary" @click="stopSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import * as api from '@/api'
export default {
  props: {
    stopVisible: {
      type: Boolean,
      default: false
    },
    license_id: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      stopForm:{
        reason: ''
      },
    }
  },
  methods: {
    
    stopClose(){
      this.$emit('cancel')
    },
    
    stopSubmit(){
      console.log('stopSubmit: ')
      this.$validator.validateAll().then(valid => {
        console.log('stopSubmit: ', valid)
        if (valid) {
          console.log('验证通过: ', valid)
          this.licenseTermination()
        }
      })
    },
    
    async licenseTermination() {
      const { code } = await api.license(this).licenseTermination(this.stopForm, this.license_id)
      if (code === 0) {
        console.log('调即可')
        this.$message.success('操作成功')
        
        this.stopForm.reason =''
        this.$emit('sure')
      }
    },
  },   
}
</script>

<style lang="stylus">

</style>